package emb 
{
	import flash.geom.Point;
	import flash.media.Sound;
	import flash.media.SoundTransform;
	/**
	 * ...
	 * @author ...
	 */
	public class SoundLib 
	{
		[Embed(source = '../../assets/sound/tfire64.mp3')]
		private static var ExlplodeSound: Class;
		[Embed(source = "../../assets/sound/pickup.mp3")]
		private static var PickupSound: Class;
		[Embed(source = "../../assets/sound/shot.mp3")]
		private static var ShotSound:Class;
		
		private var snd:Vector.<Sound>;
		private var sndt:Vector.<SoundTransform>;
		
		public static const SBlowUp = 0;
		public static const SPickUp = 1;
		public static const SShotUp = 2;
		
		public static var Muted = false;//TO DO - add indicator to GUI (possibly a control)
		
		private static var instance:SoundLib;
		
		public function PlaySound(x:Number, y:Number, s:uint)
		{
			if (Muted) return;
			var dx:Number = Main.Instance().p.x - x;
			var dy:Number = Main.Instance().p.y - y;
			var vol:Number = Math.sqrt(dx * dx + dy * dy) / 600;
			if (vol > 1) return;//No need to play
			vol = Math.max(0, 1 - vol);
			var p:Point = new Point(dx, dy);
			p.normalize(1);
			sndt[s].volume = vol;
			sndt[s].pan = -p.x;
			snd[s].play(0, 0, sndt[s]);
		}
		
		public static function Instance():SoundLib
		{
			if (!instance)
				instance = new SoundLib();
			return instance;
		}
		
		public function SoundLib() 
		{
			snd = new Vector.<Sound>();
			sndt = new Vector.<SoundTransform>();
			snd.push(new ExlplodeSound() as Sound);
			sndt.push(new SoundTransform());
			snd.push(new PickupSound() as Sound);
			sndt.push(new SoundTransform());
			snd.push(new ShotSound() as Sound);
			sndt.push(new SoundTransform());
		}
		
	}

}